﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using System.Data;


    public partial class RList : AdminBase
    {
        public int _Id = 0;
        private DataTable dc = new DataTable();
            protected void Page_Load(object sender, EventArgs e)
            {
                grdbind();

            }


    public void grdbind()
    {
        using (Entities bll = new Entities())
        {

            var lfeed = from u in bll.L_RForm select u;


            if (!string.IsNullOrEmpty(Request.Params["ID"]))
            {
                _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);
                lfeed = lfeed.Where(p => p.FID == _Id);
            }



            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = lfeed.OrderByDescending(x => x.FrID).ToList();  //这里好像一定要Tolist();不然会有点错误；
            pds.AllowPaging = true;
            AspNetPager1.RecordCount = lfeed.Count(); //记录总数；
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;
            this.rptList.DataSource = pds;
            this.rptList.DataBind();
        }
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {   //当页面页数改变时，执行这个方法；
                AspNetPager1.CurrentPageIndex = e.NewPageIndex;
                grdbind();
            }
         

            protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text);

                Entities bll = new Entities();
                L_RForm model = bll.L_RForm.First(p => p.FrID == id);

                switch (e.CommandName.ToLower())
                {

                    case "del":
                        bll.L_RForm.Remove(model);

                        break;

                }

                bll.SaveChanges();
                grdbind();
              
                //RptBind("Id>0" + CombSqlTxt(this.kindId, this.classId, this.keywords, this.property), "AddTime desc");
            }


    public string ToFName(string ClassId)
    {
        string result = "";
        try
        {

            int intClassId = Convert.ToInt32(ClassId);
            Entities db = new Entities();
            var LClass = db.L_Form.SingleOrDefault(p => p.FID == intClassId);
            result = LClass.FNmae;
        }
        catch (Exception ex)
        {
            result = "该表单不存在";
        }

        return result;
    }


}
  
